/*****************************************************************************
 * Copyright (c) 2007, Ping Identity
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Ping Identity, nor the names of its contributors
 *       may be used to endorse or promote products derived from this software
 *       without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY PING IDENTITY ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
 * NO EVENT SHALL PING IDENTITY BE LIABLE FOR ANY DIRECT, INDIRECT, 
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *****************************************************************************/

/*!
 * @header Internal context structure and management
 * @discussion
 *	This file defines the current structure of the context, as well as several
 *	useful internal methods for activities such as logging. Applications should
 *	not use this file, as nothing within this file is currently guaranteed
 *	between releases.
 */
#ifndef _CONTEXT_INTERNAL_H
#define _CONTEXT_INTERNAL_H
#include <xmlsec/xmlsec.h>
#include <xmlsec/xmltree.h>
#include <xmlsec/xmldsig.h>
#include <xmlsec/crypto.h>

#include "context.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Internal context structure. Directly accessing this structure will break 
 binary compatibility. */
struct ic_context_t
{
	xmlSecKeysMngrPtr			key_manager;
	time_t						time;
	ic_logger_func				logger;
	ic_attribute_reporting_func	attr_reporter;
	ic_replay_detection_func    detector;
	ic_token_processing_func				processor;
	unsigned int					input_max_size;
	void						*logger_context;
	void						*attr_context;
	void						*detector_context;
	xmlChar						*audience;
};

/* helper methods for logging */

/*!
 * @function log_reason
 * @abstract internal helper method to report message to logging callback
 */
void log_reason(struct ic_context_t *ctx, log_level level, const char *reason);

/*!
 * @function log_error
 * @abstract internal helper method to report error messages to logging
 *	callback.
 * @discussion this method calls log_reason with a level of ERROR_LVL
 */
void log_error(struct ic_context_t *ctx, const char *reason);
/*!
 * @function log_reasonf
 * @abstract internal helper method to report formatted messages to logging 
 *	callback.
 * @discussion this method uses reasonstr as a printf format string and logs
 *	the result. There is a limit of 1024 characters, which will make logging
 *	of large amounts of data (like raw traffic) fail.
 */
void log_reasonf(struct ic_context_t *ctx, log_level level, const char *reasonstr, ...);
	
/*!
 * @function log_vreasonf
 * @abstract internal helper method to report formatted messages to logging 
 *	callback.
 * @discussion see log_reasonf.
 */
void log_vreasonf(struct ic_context_t *ctx, log_level level, const char *reasonstr, va_list args);	

#ifdef __cplusplus
}
#endif
#endif /* _CONTEXT_INTERNAL_H */
